package com.xln.util;


import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private Integer code;
    private String message;
    private T data;

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(){
    }

    public static <T> Result<T> success() {
        Result result = new Result<>();
        result.setCode(ResEnum.SUCCESS.getCode());
        result.setMessage(ResEnum.SUCCESS.getMessage());
        return result;
    }

    public static <T> Result<T> success(ResEnum resEnum) {
        return new Result<>(resEnum.getCode(), resEnum.getMessage(), null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResEnum.SUCCESS.getCode(), ResEnum.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> success(ResEnum resEnum, T data) {
        return new Result<>(resEnum.getCode(), resEnum.getMessage(), data);
    }

    public static <T> Result<T> error() {
        return new Result<>(ResEnum.ERROR.getCode(), ResEnum.ERROR.getMessage(), null);
    }

    public static <T> Result<T> error(ResEnum resEnum) {
        return new Result<>(resEnum.getCode(), resEnum.getMessage(), null);
    }

    public static <T> Result<T> error(ResEnum resEnum, T data) {
        return new Result<>(resEnum.getCode(), resEnum.getMessage(), data);
    }



}
